package com.sikaryofficial.information.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.information.manager.ArticleManager;
import com.sikaryofficial.system.api.model.infomation.ArticleDTO;
import com.sikaryofficial.system.api.model.infomation.ArticleListReq;
import com.sikaryofficial.system.api.model.infomation.KolListReq;
import com.sikaryofficial.system.api.model.infomation.StatuteListReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 文章Controller
 *
 * @author qinjinyuan
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章服务")
public class ArticleController extends BaseController {
    @Autowired
    private ArticleManager articleManager;
    /**
     * kol文章分页列表
     */
    @PostMapping("/kolListPage")
    @ApiOperation("kol文章分页列表")
    public PageResult<ArticleDTO> kolListPage(@Validated @RequestBody KolListReq req) {
        IPage<ArticleDTO> page = articleManager.kolListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }
    /**
     * 法律法规分页列表
     */
    @PostMapping("/statuteListPage")
    @ApiOperation("法律法规分页列表")
    public PageResult<ArticleDTO> statuteListPage(@Validated @RequestBody StatuteListReq req) {
        IPage<ArticleDTO> page = articleManager.statuteListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 查询文章列表
     */
    @GetMapping("/owner/latest")
    @ApiOperation("文章分页列表")
    public R<List<ArticleDTO>> ownerLatest() {
        return R.ok(articleManager.ownerLatest());
    }
    /**
     * 查询文章列表
     */
    @PostMapping("/listPage")
    @ApiOperation("文章分页列表")
    public PageResult<ArticleDTO> listPage(@Validated @RequestBody ArticleListReq req) {
        IPage<ArticleDTO> page = articleManager.listPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 获取文章详细信息
     */
    @GetMapping(value = "/{articleId}")
    @ApiOperation("获取文章详细信息")
    public R<ArticleDTO> getInfo(@PathVariable(value = "articleId") Long articleId) {
        return R.ok(articleManager.getInfo(articleId));
    }

    /**
     * 获取文章详细信息
     */
    @GetMapping(value = "/simple/{articleId}")
    @ApiOperation("获取文章简单详细信息")
    public R<ArticleDTO> getSimpleInfo(@PathVariable(value = "articleId") Long articleId) {
        return R.ok(articleManager.getSimpleInfo(articleId));
    }
    /**
     * 删除文章
     */
    @GetMapping("/delete/{articleIds}")
    @ApiOperation("删除文章")
    public R<Boolean> remove(@PathVariable(value = "articleIds") String articleIds) {
        return R.ok(articleManager.remove(articleIds));
    }

    /**
     * 删除个人文章
     */
    @GetMapping("/removeOwner/{articleIds}")
    @ApiOperation("删除文章")
    public R<Boolean> removeOwner(@PathVariable(value = "articleIds") String articleIds) {
        return R.ok(articleManager.removeOwner(articleIds));
    }
}
